<?php

namespace {{invokerPackage}};

class Client
{
{{#apiInfo}}
    {{#apis}}
    {{#supportPhp7}}/** @var \{{apiPackage}}\{{classname}} */{{/supportPhp7}}
    public {{^supportPhp7}}readonly \{{apiPackage}}\{{classname}} {{/supportPhp7}}${{classNameCamelCase}};
    {{/apis}}

    /**
     * Constructor
     */
    public function __construct(
{{#hasOAuthMethods}}
{{#authMethods}}
{{#-first}}
        string $clientId = null,
        string $clientSecret = null,
        string $tokenUrl = '{{tokenUrl}}',
{{/-first}}
{{/authMethods}}
{{/hasOAuthMethods}}
        {{#clientState}}
        string ${{.}} = null,
        {{/clientState}}
        {{#clientStateWithExamples}}
        string ${{name}} = null,
        {{/clientStateWithExamples}}
        {{#apiKeyMethods}}
        string ${{> api_key_name}} = null,
        {{/apiKeyMethods}}
        bool $verifySsl = null,
        string $host = '{{basePath}}',
        \{{invokerPackage}}\Configuration $config = null
    )
    {
        if ($config == null) {
            $config = new \{{invokerPackage}}\Configuration(
                {{^supportPhp7}}
                {{#clientState}}
                {{.}}: ${{.}},
                {{/clientState}}
                {{#clientStateWithExamples}}
                {{name}}: ${{name}},
                {{/clientStateWithExamples}}
                {{#apiKeyMethods}}
                {{> api_key_name}}: ${{> api_key_name}},
                {{/apiKeyMethods}}
                {{/supportPhp7}}
            );
        {{#supportPhp7}}
        {{#clientStateSetterGetterCamelCase}}
            $config->{{setter}}(${{state}});
        {{/clientStateSetterGetterCamelCase}}
        {{#clientStateWithExamplesSetterGetterCamelCase}}
            $config->{{setter}}(${{state}});
        {{/clientStateWithExamplesSetterGetterCamelCase}}
        {{#apiKeyMethods}}
            $config->setApiKey("{{keyParamName}}", ${{> api_key_name}});
        {{/apiKeyMethods}}
        {{/supportPhp7}}
            if ($host !== null) $config->setHost($host);
            if ($verifySsl !== null) $config->setVerifySsl($verifySsl);
{{#hasOAuthMethods}}
            if ($tokenUrl !== null) $config->setTokenUrl($tokenUrl);
            if ($clientId !== null) $config->setClientId($clientId);
            if ($clientSecret !== null) $config->setClientSecret($clientSecret);
{{/hasOAuthMethods}}
        }
        {{#apis}}
        $this->{{classNameCamelCase}} = new \{{apiPackage}}\{{classname}}($config);
        {{/apis}}
{{/apiInfo}}
    }
}
